<!--
 * @Descripttion: 报考页
 * @version: 
 * @Author: Bruce
 * @Date: 2020-11-02 14:26:13
 * @LastEditors: Bruce
 * @LastEditTime: 2020-11-05 17:15:29
-->


<template>
	<div class="container tableFlex">
		<my-table :tableTitle="tableTitle" :tableData="tableData" :loading="loading">
			<template v-slot:action="{ row }">
				<el-button type="text" size="small" @click="goDetails(row)">查看详细</el-button>
				<el-button v-if="row.state === '审核通过'" type="text" size="small" @click="goPay(row)">缴费</el-button>
			</template>
		</my-table>
		<page :currentPage.sync="currentPage" :total="total" :pageSize="size"></page>
	</div>
</template>

<script>
	import {
		list
	} from "@/api/apiList/user.js"
	export default {
		name:"signup",
		data() {
			return {
				currentPage: 1, //当前页数
				total: 0, //总数
				size: 10, //每页条数
				loading: false,
				tableTitle: [{ //表单标题
						label: '考试名称',
						prop: 'ename'
					},
					{
						label: '考试时间',
						prop: 'eemtm'
					},
					{
						label: '准考证号',//
						prop: 'zkh'
					},
					{
						label: '考试费',
						prop: 'ecost'
					},
					{
						label: '报名开始时间',
						prop: 'estar'
					},
					{
						label: '报名截止时间',
						prop: 'eddle'
					},
					{
						label: '缴费时间',
						prop: 'pytm'
					},
					{
						label: '考生得分',
						prop: 'score'
					},
					{
						label: '通过情况',
						prop: 'statn'
					},
					{
						label: '状态',
						prop: 'state'
					},
					{
						label: '审核结果',
						prop: 'reason'
					},
				],
				tableData: [] //表格数据
			}
		},
		watch: {
			currentPage: {
				async handler(currentPage) {
					this.loading = true
					let res = await this.API_list(currentPage, this.size)

					let {
						current,
						records
					} = res.data.data
					this.currentPage = current
					this.total = records.length
					this.tableData = this.stateFilter(records)
					this.loading = false
				},
				immediate: true
			}
		},
		methods: {
			async API_list(current, size) {
				let result = {
					page: {
						current, //第几页
						size //每页条数
					}
				}
				return await list(result)
			},
			goDetails(row) { //去报名表页
				this.$store.commit("signUpFormDetails/UPDATE_ROW",JSON.stringify(row))
				this.$router.push({
					path: "/SignUpFormDetails",
					query: {
						eid: row.eid,
						id: row.id,
					}
				})
			},
			goPay(row) {
				// console.log(row)
				this.$router.push({
					path: "/pay",
					query: {
						id: row.id,
					}
				})
			},
			stateFilter(arr){//过滤状态
				return arr.map((item)=>{
					let obj = {}
					if(item.state === 1){
						item.state = "待审核"
						obj = item
					}else if(item.state === 2){
						item.state = "审核通过"
						obj = item
					}else if(item.state === 3){
						item.state = "审核不通过"
						obj = item
					}else if(item.state === 4){
						item.state = "已缴费"
						obj = item
					}else if(item.state === 5){
						item.state = "已出准考证"
						obj = item
					}else if(item.state === 6){
						item.state = "已出证书"
						obj = item
					}
					return obj
				})
			}
		},
		async activated(){//激活状态
			this.loading = true
			let res = await this.API_list(this.currentPage, this.size)
			
			let {
				current,
				records
			} = res.data.data
			this.currentPage = current
			this.total = records.length
			this.tableData = this.stateFilter(records)
			this.loading = false
		}
	}
</script>

<style>
</style>

